#ifndef VERIFIER_TWO_STAGE_H
#define VERIFIER_TWO_STAGE_H

#include "Verifier_Of_Splits.h"

// kinds of badly split cluster pairs
struct Bad_Split {
    typedef enum {
        OK,
        MOVE_C_TO_AB,
        MOVE_D_TO_AB,
        MOVE_A_TO_CD,
        MOVE_B_TO_CD,
        MOVE_A_TO_S,
        MOVE_B_TO_S
    } Type;
};

class Verifier_Two_Stage : public Verifier_Of_Splits {
public:
    Verifier_Two_Stage(double min_ratio,
                       Cluster_Metric metric,
                       Splitter& splitter);
    bool verify(vector<Cluster*> &children);

private:
    Bad_Split::Type check(Cluster *a, Cluster *b, Cluster *c, Cluster *d);
    Bad_Split::Type check(Cluster *S, Cluster *a, Cluster *b);
    void fix(Bad_Split::Type bad_split_type,
             Cluster*& S1, Cluster*& S2,
             Cluster *a, Cluster *b, Cluster *c, Cluster *d);
    void fix(Bad_Split::Type bad_split_type,
             Cluster *S, Cluster*& ab,
             Cluster *a, Cluster *b);
    void is_stale(Cluster *c);
    void delete_stale_clusters();

    double min_good_split_ratio;
    std::vector<Cluster*> stale_clusters;

    Cluster_Metric cluster_metric;
    Splitter cluster_splitter;
};

#endif
